<template>
	<view class="liquorCardManage">
		<view class="manageItemBox" v-if="days">
			<view class="manageItem" @tap="settimgTwoGo">
				<view class="left">
					<view class="tit">酒卡转赠设置</view>
				</view>
				<u-icon name="arrow-right" color="#999999" size="20"></u-icon>
			</view>
			<view class="manageItem">
				<view class="left">
					<view class="tit">联系我</view>
				</view>
				<u-icon name="arrow-right" color="#999999" size="20"></u-icon>
			</view>
			<view class="manageItem" @click="choiceDays">
				<view class="left">
					<view class="tit">酒卡有效期</view>
					<view class="tips">超过有效期将转为存酒,默认30天</view>
				</view>
				<view class="right">{{days}}天</view>
				<u-icon name="arrow-right" color="#999999" size="20"></u-icon>
			</view>
		</view>
		
		<!-- 天数选择 -->
		<u-select v-model="daysShow" :list="daysList" title="选择酒卡有效期" @confirm="daysOk"></u-select>
	</view>
</template>

<script>
	export default{
		data() {
			return{
				// 酒卡有效期
				days:null,
				newDays:null,
				// 酒卡失效时间
				failureTime:null,
				// 受赠人设置  1所有人可领 0好友可领
				givenAll:null,
				daysShow:false,
				daysList:[
					{
						value: '30',
						label: '30天'
					},
					{
						value: '60',
						label: '60天'
					}
				]
			}
		},
		onLoad: function (option) {
			this.getSetting();
		},
		methods:{
			// 选择天数
			choiceDays(){
				this.daysShow = true;
			},
			daysOk(val){
				this.newDays = val[0].value;
				this.settingGo();
			},
			// 获取设置
			getSetting(){
				this.apiget('/mall/storage-liquor/get-setting',{}).then(res => {
					if (res.data.status == 200) {
						this.days = res.data.data.effective_days;
						this.failureTime = res.data.data.given_failure_hours;
						this.givenAll = res.data.data.given_all;
					}
				})
			},
			// 保存设置
			settingGo(){
				var _this = this;
				this.apipost('/mall/storage-liquor/setting', {effective_days:this.newDays,given_failure_hours:this.failureTime,given_all:this.givenAll}).then(res => {
					if (res.data.status == 200) {
						setTimeout(function (){
							_this.getSetting();
						}, 1000);
					}
				})
			},
			// 酒卡转赠设置
			settimgTwoGo(){
				uni.navigateTo({
					url: './liquorCardManageTwo'
				});
			},
		}
	}
</script>

<style lang="scss">
	.liquorCardManage{
		min-height: 100%;
		padding-top: 24rpx;
		background: #F8F8FA;
		
		.manageItemBox{
			padding: 0 32rpx;
			background-color: #fff;
			
			.manageItem{
				display: flex;
				align-items: center;
				padding: 28rpx 0;
				box-shadow: inset 0px -0.5px 0px #F5F5F5;
				
				.left{
					flex: 1;
					width: 1px;
					
					.tit{
						font-size: 28rpx;
						line-height: 44rpx;
						color: #333;
					}
					.tips{
						font-size: 24rpx;
						line-height: 40rpx;
						color: #999;
					}
				}
				
				.right{
					margin-right: 24rpx;
					font-size: 28rpx;
					line-height: 44rpx;
					color: #333;
				}
			}
		}
	}
</style>
